package controller;

import javax.swing.JProgressBar;
import javax.swing.JTextPane;

import model.BinSetVariables;
import model.MonteCarloSimulation;

/**
 * @author Estelle && Marie
 * This class is just to use for setting the text our main window and gets the result for a simulation with thread.
 * 
 */

public class WithoutThread {

	JProgressBar bar;
	double res=0;
	BinSetVariables binsetvariables;
	
	public WithoutThread(BinSetVariables binsetvariable, JTextPane text, JProgressBar barre){
		
		long a,b;
		double total;
		this.binsetvariables = binsetvariable;
		StringBuilder  buff = new StringBuilder();
		this.bar = barre ;
		a = System.nanoTime();
		
		MonteCarloSimulation m = new MonteCarloSimulation(binsetvariables, bar);
		res = m.MonteCarloStandardOption(binsetvariables);
		
		//we calcule the duration of our execution
		
		
		b = System.nanoTime();
		total = (b-a)/1000000000.0;
		
		//we display the result of the simulation in our main window
		buff.append("Result : ").append(res).append("\n Beginning time : ").append(b).append("\n Ending time : ").append(b);
		buff.append("\nTotal time : " ).append(total).append(" sec");
		
		text.setText(buff.toString());
		barre.setValue(barre.getMaximum());
	}
}
